package com.aaa.mbs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.entity.MemberLevel;
import com.aaa.mbs.service.MemberLevelService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (MemberLevel)表控制层
 *
 * @author makejava
 * @since 2020-12-05 09:26:40
 */
@RestController
@RequestMapping("memberLevel")
public class MemberLevelController {
    /**
     * 服务对象
     */
    @Resource
    private MemberLevelService memberLevelService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public MemberLevel selectOne(Long id) {
        return this.memberLevelService.queryById(id);
    }

    /**
     * 查询指定行数据
     *
     * @param pageNo      查询起始位置
     * @param pageSize    查询条数
     * @param memberLevel
     * @return Result ---- Result.getData() 对象列表
     */
    @GetMapping("queryAllByParam")
    public Result queryAllByParam(Integer pageNo, Integer pageSize, MemberLevel memberLevel) {
        return this.memberLevelService.queryAllByParam(pageNo, pageSize, memberLevel);
    }

    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Long id) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.memberLevelService.deleteById(id));
    }

    /**
     * 更新
     *
     * @param @param memberLevel 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody MemberLevel memberLevel) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.memberLevelService.update(memberLevel));
    }

    /**
     * 添加
     *
     * @param @param memberLevel 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody MemberLevel memberLevel) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.memberLevelService.insert(memberLevel));
    }
}